#pragma once
#include <curl/curl.h>
#include <string>
#include <iostream>
#include <functional>

class HttpPost
{
public:
    
    ~HttpPost();
    static HttpPost* getInstance(){
        static HttpPost instance;
        return &instance;
    };

    void resetHeader(){
        if(headers_ != NULL){
            delete headers_;
            headers_ = NULL;
        }
        return;
    };

    void setHeader(const char* list){
        headers_=curl_slist_append(headers_, list);
        return;
    };

    bool curlPostReq(const std::string& url,const std::string &postParams);

    void regProcessCall(std::function<void(std::string & reply)> callback){
        if(!replyProcessCall_)
            replyProcessCall_ = callback;
    }
private:
    /* data */
    HttpPost();
    // static HttpPost instance;
    struct curl_slist* headers_ = NULL;
    std::function<void(std::string & reply)> replyProcessCall_;
};

